package com.tds.springbootdemo2.dto;

import cn.hutool.core.util.StrUtil;
import com.tds.springbootdemo2.util.SignTools;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

@Data
public class AsyncOfflinePayDTO implements Serializable {


    /**
     * zityId
     */
    private String zityId;

    /**
     * 时间挫
     */
    private String time;

    /**
     * 设备编号
     */
    private String devNo;

    /**
     * 签名
     */
    private String sign;

    /**
     * 盐
     */
    private String salt;

    /**
     * 金额
     */
    private BigDecimal amount;

    /**
     * 卡号
     */
    private String cardNo;


    /**
     * 唯一ID
     */
    private String uuid;

    /**
     * 人脸图片地址
     */
    private String face_url;


    /**
     * 支付宝刷脸付token
     */
    private String ftoken;

    /**
     * 支付宝设备加签
     */
    private String terminalParams;


    public void genereateSign(String signKey) throws Exception {
        Map<String, Object> valiateSignMap = new TreeMap<>(Comparator.naturalOrder());;
        valiateSignMap.put("zityId", this.zityId);
        if(StrUtil.isNotEmpty(this.cardNo) && !"0".equals(cardNo)){
            valiateSignMap.put("cardNo", this.cardNo);
        }
        valiateSignMap.put("devNo", this.devNo);
        // 盐值
        valiateSignMap.put("salt", this.salt);
        if(StrUtil.isNotEmpty(this.uuid)){
            valiateSignMap.put("uuid", this.uuid);
        }
        // 时间
        valiateSignMap.put("time", this.time);
        if( this.amount != null){
            valiateSignMap.put("amount", this.amount);
        }
        // key
        valiateSignMap.put("key", signKey);
        this.sign = SignTools.encryptMapMD5(valiateSignMap);
    }
}
